package com.ding.dailyup.repository;

import com.ding.dailyup.model.UserCollectStrategy;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface UserCollectStrategyRepository
		extends JpaRepository<UserCollectStrategy, Long> {

	Optional<List<UserCollectStrategy>> findAllByUserIdAndStatusOrderByIdDesc(
			Long userId, int status);

	Optional<UserCollectStrategy> findByUserIdAndStrategyId(Long userId,
			Long strategyId);

	@Query(nativeQuery = true, value = "update user_collect_strategy set status = 0 where userId = :userId and strategyId = :strategyId")
	@Modifying
	void cancelCollect(@Param(value = "userId") Long userId,
			@Param(value = "strategyId") Long strategyId);
}
